package model;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import utils.Utils;

public class CarnetCommandes extends Observable{
	
	
	public static CarnetCommandes getInstance(){
		if(cm == null){
			cm = new CarnetCommandes();
		}
		return cm;
	}
	
	
	public void addCommande(Commande comm){
		boolean isAdded = false;
		isAdded = commandes.add(comm);
		if(isAdded){
			comm = getLastCommande();
			comm.setNumber(Utils.generateConfirmationNumber());
			comm.setDateTimeAdded(Utils.getStrCurrentDateTime());
			setChanged();
			notifyObservers(comm);
		}
	}
	
	public Commande getLastCommande(){
		Commande comm = null;
		if(size() > 0 ){
			comm = commandes.get(size() - 1);
		}
		return comm;
	}
	
	public int size(){
		return commandes.size();
	}
	
	
		
	private CarnetCommandes(){
		commandes = new ArrayList<Commande>();
	}
	
	public List<Commande> getCarnetDeCommande(){
		return commandes;
	}
	
	private List<Commande> commandes;
	private static CarnetCommandes cm;
	
}
